
// 全局函数

let a = 100 ;
console.log( a , isFinite( a ) ); // is finite

let b = 0 ;
let c = '今天天气不咋地' ;

let e = a / b ;
console.log( e , isFinite( e ) );

let d = a / c ;
console.log( d , isNaN( d ) ); // is not a number : 是 "不是一个数字"

console.log( '- - - - - - - - - - - - - - -' );

let s = '0xFFFF' ;
let t = parseInt( s , 16 ); // radix : 基数
console.log( t );

let u = '10010' ;
console.log( u ,typeof(u) );
let v = parseInt( u ) ;
console.log( v ,typeof(v) );

let x = '3.1415926' ;
console.log( x ,typeof(x) );
let y = parseFloat( x ) ;
console.log( y ,typeof(y) );

console.log( '- - - - - - - - - - - - - - -' );

let expression = '5 * ( 7 - 2 + 1 ) / 3' ;
let result = eval( expression );
console.log( expression , '=' , result );

let json1 = '[ 10 , 20 , 30 , 40 ]' ;
console.log( Array.isArray( json1 ) , typeof( json1 ) );
let arr = eval( json1 );
console.log( Array.isArray( arr ) , typeof( arr ) );

let json2 = '{id:1001,name:"张三丰",age:108}' ;
console.log( typeof( json2 ) );
let obj = eval( '(' + json2 + ')');
console.log( typeof( obj ) );

// let str = uneval( obj ); // node.js 的 global 中未提供该函数
// console.log( str );

console.log( '- - - - - - - - - - - - - - -' );

// URI : Uniform Resource Identifier , 统一资源标识(zhi)符
const uri = 'http://www.baidu.com/s?wd=张三丰' ;
console.log( uri );

let encoded = encodeURI( uri ); // 对 URI 进行编码(encode)
console.log( encoded );

let decoded = decodeURI( encoded ); // 对被编码的URI进行解码(decode)操作
console.log( decoded );

console.log( '- - - - - - - - - - - - - - -' );

let euc =  encodeURIComponent( uri );
console.log( euc );

let duc =  decodeURIComponent( euc );
console.log( duc );
